package com.plm.maque.controller;


import com.alibaba.fastjson.JSON;
import com.plm.maque.entity.User;
import com.plm.maque.service.UserService;
import com.plm.maque.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author Limi Pan
 * @since 2018-12-30
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/list")
    @ResponseBody
    public PageUtils list(@RequestParam Map<String, Object> params){
        return userService.queryPage(params);
    }

    @GetMapping("/getUser")
    @ResponseBody
    public User getUser(@RequestParam Map<String, Object> params){
        return userService.getUser(params);
    }

    @PostMapping("/create")
    public User create(@RequestParam Map<String, Object> params){
        User user = JSON.parseObject(JSON.toJSONString(params), User.class);
        userService.save(user);
        return user;
    }
}
